/**********************************************************************
* Filename: Bilhete.java
* Created: 2013/05/29
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.airNova.businessLayer;

import java.util.Set;

import org.quasar.airNova.persistenceLayer.Database;

public class Bilhete
{
	
	/***********************************************************
	* @return all instances of class Bilhete
	***********************************************************/
	public static Set<Bilhete> allInstances()
	{
		return Database.allInstances(Bilhete.class);
	}
	
	private int lugar;
	private String nome_completo;
	private String primeiro_nome;
	private String ultimo_nome;
	private Reserva reserva;
	private Classe classe;
	private Realizacao realizacao;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Bilhete()
	{
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param lugar the lugar to initialize
	* @param nome_completo the nome_completo to initialize
	* @param primeiro_nome the primeiro_nome to initialize
	* @param ultimo_nome the ultimo_nome to initialize
	* @param reserva the reserva to initialize
	* @param classe the classe to initialize
	* @param realizacao the realizacao to initialize
	**********************************************************************/
	public Bilhete(int lugar, String nome_completo, String primeiro_nome, String ultimo_nome, Reserva reserva, Classe classe, Realizacao realizacao)
	{
		this.lugar = lugar;
		this.nome_completo = nome_completo;
		this.primeiro_nome = primeiro_nome;
		this.ultimo_nome = ultimo_nome;
		this.reserva = reserva;
		this.classe = classe;
		this.realizacao = realizacao;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the lugar of the bilhete
	**********************************************************************/
	public int lugar()
	{
		return lugar;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param lugar the lugar to set
	**********************************************************************/
	public void setLugar(int lugar)
	{
		this.lugar = lugar;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the nome_completo of the bilhete
	**********************************************************************/
	public String nome_completo()
	{
		return nome_completo;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param nome_completo the nome_completo to set
	**********************************************************************/
	public void setNome_completo(String nome_completo)
	{
		this.nome_completo = nome_completo;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the primeiro_nome of the bilhete
	**********************************************************************/
	public String primeiro_nome()
	{
		return primeiro_nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param primeiro_nome the primeiro_nome to set
	**********************************************************************/
	public void setPrimeiro_nome(String primeiro_nome)
	{
		this.primeiro_nome = primeiro_nome;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the ultimo_nome of the bilhete
	**********************************************************************/
	public String ultimo_nome()
	{
		return ultimo_nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param ultimo_nome the ultimo_nome to set
	**********************************************************************/
	public void setUltimo_nome(String ultimo_nome)
	{
		this.ultimo_nome = ultimo_nome;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Bilhete[*] <-> Reserva[1]
	* @return the reserva of the bilhete
	**********************************************************************/
	public Reserva reserva()
	{
		return reserva;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Bilhete[*] <-> Reserva[1]
	* @param reserva the reserva to set
	**********************************************************************/
	public void setReserva(Reserva reserva)
	{
		this.reserva = reserva;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Bilhete[*] <-> Classe[1]
	* @return the classe of the bilhete
	**********************************************************************/
	public Classe classe()
	{
		return classe;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Bilhete[*] <-> Classe[1]
	* @param classe the classe to set
	**********************************************************************/
	public void setClasse(Classe classe)
	{
		this.classe = classe;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Bilhete[*] <-> Realizacao[1]
	* @return the realizacao of the bilhete
	**********************************************************************/
	public Realizacao realizacao()
	{
		return realizacao;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Bilhete[*] <-> Realizacao[1]
	* @param realizacao the realizacao to set
	**********************************************************************/
	public void setRealizacao(Realizacao realizacao)
	{
		this.realizacao = realizacao;
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	**********************************************************************/
	public void ApagarBilhete()
	{
		if(this.reserva.bilhetes().size() == 1){
			Database.delete(this.reserva);
			Database.delete(this);
			
		}
		else 
			Database.delete(this);
			
		Database.close();

	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	**********************************************************************/
	public Aeroporto Destino()
	{
		//	TODO
		//	return self.realizacao.realiza_se.chegada
		return null;
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	**********************************************************************/
	public String Nome_completo()
	{
		//	TODO
		//	return self.primeiro_nome.concat(' ').concat(self.ultimo_nome)
		return null;
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	**********************************************************************/
	public Aeroporto Origem()
	{
		//	TODO
		//	return self.realizacao.realiza_se.partida
		return null;
	}
	
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Bilhete [lugar=" + lugar + ", nome_completo=" + nome_completo + ", primeiro_nome=" + primeiro_nome + ", ultimo_nome=" + ultimo_nome + ", reserva=" + reserva + ", classe=" + classe + ", realizacao=" + realizacao + "]";
	}
	
	//	-------------------------------------------------------------------------------
	//	INVARIANTS (TODO)
	/*
	inv reservaEmitidaSeCartaoExiste
		if (self.reserva->notEmpty and (self.reserva.pagamento = EstadoPagamento::efectuado)) then self.reserva.cartaoCredito->notEmpty else true endif
	
	inv bilheteCompradoParaUmAviaoTemDeTerUmaClasseEOProprioAviaoTemDeTerEssaClasseDefinida
		self.realizacao.aviao.classe->includes(self.classe)
	
	*/
}
